<?php include ("checkLanguage.php");?>

<p><b><i><?=$this->aDisplayedContent['error']?></i></b></p>
<p>
<form action="index.php?co=newPage" method="post"><input type="submit"
        name="newPage" value="Neue Seite anlegen" align="right" /></form>
</p>

<table>
<tr> 
                <td colspan="6" align="right">Sprache ist: <input type="text"id="lid" style="font-size: 92%" name="lid" value="<?=$sDefaultS?>" size="7" disabled="disabled"></td>
                </tr>
                <tr><td><br></td></tr>
</table>

<link rel="stylesheet" href="./content/template/css/cms_sortable.css" type="text/css" media="screen" />
<!-- <script src="../js/js/jquery-1.7.2.min.js"> </script>-->
<script src="../js/js/jquery-ui-1.8.21.custom.min.js"></script>
<script src="../js/jquery.mjs.nestedSortable.js"></script>   
 
<script>

    $(document).ready(function(){
    	$(".sortable").css({'display': 'block'});
        	$('.sortable').nestedSortable({
            handle: 'div',
            items: 'li',
            toleranceElement: '> div',
            maxLevels: '2',
            update: function(event, ui) {
                var pageList = $(this).nestedSortable('serialize', {startDepthCount: 0}); 
                        $.ajax({
                                type: "POST",
                                url:  "index.php?a=ajax&co=pageStructure&m=updatePageStructure",
                                data: pageList,
                                success: function(data){
                    
                  }
                        })   
            }
        });

    });
</script>    

<style>
.sortable{
display: none;
}

</style>
<?php showPageStructure($this->aDisplayedContent['nestedPageStructure'], " class = sortable");?>

<?php function showPageStructure($aPageStructureNested, $sClass = ""){
    
    echo "<ol$sClass>";
    foreach ($aPageStructureNested as $aPage){
        $iPageID = $aPage['id'];
        $sPageName = $aPage['name'];
        $sDeleteImage = '';
        //ID 2 is mainpage, it may not be deleted
        if($aPage['id'] != 2){
            $sDeleteImage = "<a href='index.php?co=pageStructure&m=deletePage&id=$iPageID'><img src='../image/remove.png' align=right width=20px height=20px></a>";
        }
        
        $sController = $aPage['type'];
        
        echo "<li id=list_'$iPageID'><div style=\"border:1px solid white\"><a href='index.php?co=$sController&id=$iPageID'>$sPageName</a>$sDeleteImage</div>";
        if(!empty($aPage['subPages'])){
            showPageStructure($aPage['subPages']);
     }?></li><?php 
    }
    echo "</ol>";
  }
?>

<noscript>
<form action="index.php?co=pageStructure&method=savePageStructure"
	method="post"><?php foreach($this->aDisplayedContent['arrayPageStructure'] as $aElement){?>

<table>
<?php if($aElement['id'] == 2){?>
<tr>
		<th></th>
		<th>Unterseite von&nbsp;&nbsp;&nbsp;</th>
		<th>Pos.&nbsp;&nbsp;&nbsp;</th>
		<th>Seitentitel</th>
		<th>Sichtbar?</th>
	</tr>
	<?php }
	if($aElement['parent'] == ""){ $sClass = "class=\"topLevelPage\"";}else{ $sClass = "";}
	?>
	<tr <?=$sClass?>>
		<td width="<?=$aElement['level']*15?>" <?=$sClass?>></td>
		<td <?=$sClass?>><select style="font-size: 92%" name="parent<?=$aElement['id'] ?>">
			<option value="">------------------------------</option>
			<?php foreach($this->aDisplayedContent['arrayPageStructure'] as $aParent){
			    if($aElement['id'] != 2){
			        if($aParent['id'] != $aElement['id']){?>

			<option value="<?=$aParent['id']?>"
			<?php if($aParent['id']==$aElement['parent']){echo "selected";}?>><?=$aParent['name']?></option>

			<?php }}}?>
		</select>&nbsp;&nbsp;&nbsp;</td>
		<td <?=$sClass?>><input size="2px" type="text" name="position<?=$aElement['id'] ?>"
			maxlength="2" class="text" value="<?=$aElement['position']?>" />&nbsp;&nbsp;&nbsp;</td>
		<td <?=$sClass?>><input type="text" name="name<?=$aElement['id'] ?>"
			size="30" maxlength="50" class="text" value="<?=$aElement['name']?>" /></td>
		<td <?=$sClass?>><select style="font-size: 92%" name="visible<?=$aElement['id'] ?>">
			<option value="1"
			<?php if($aElement['visible'] == 1) echo "selected";?>>ja</option>
			<option value="0"
			<?php if($aElement['visible'] == 0) echo "selected";?>>nein</option>
		</select></td>

			
		<td <?=$sClass?>>
			<a
			href='<?="index.php?co=pageStructure&method=deletePage&id=".$aElement['id']?>'><img
			src='../image/remove.png' align=right width=30px height=30px alt="Seite L&ouml;schen"></a>
			</td>

	</tr>
</table>

			<?php }?>

<p><input type="submit" name="newPage" value="&Auml;nderungen speichern"
	align="right" /></p>
</form>
</noscript>
